<?php
/**
 * Introduction: 售后
 * @author: 杨陈鹏
 * @date: 2016/4/1 08:42
 * @email: yangchenpeng@cdlinglu.com
 *
 */
namespace Admin\Controller\AfterSales;


use Common\Controller\Admin\CommonController;

class IndexController extends CommonController
{
    /**
     * Introduction: 售后列表
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     *
     */
    public function lists()
    {

        $logic = D('Common/AfterSales','Logic');

        $this->page = I('post.page',1);

        $this->nums = 20;

        $this->progress = I('param.progress',0);

        $where = [];

        if( $this->progress )
            $where['progress'] = $this->progress;

        $data = $logic::getData($where,'progress asc,create_time desc','*',$this->page,$this->nums);

        $this->total = $data['total'];

        $this->data = $data['data'];

        $this->display();


    }
    /**
     * Introduction: 开始处理
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     *
     */
    public function start()
    {

        $id = I('post.id');

        $mobile = I('post.mobile');

        $number = I('post.number');

        $logic = D('Common/AfterSales','Logic');

        $data['id'] = $id;
        $data['progress'] = 2;
        $data['processing_time'] = NOW_TIME;

        $result = $logic::update($data);

            if($result['code'] == 200)
            {

                $sms = new \Think\SMS\Mobile();

                $msg = "您申请的订单售后{$number}已经开始处理,我们会24小时之内联系您,请保持电话畅通";

                $sms->send($mobile,$msg);

            }

        $this->ajaxReturn($result);


    }

    /**
     * Introduction: 拒绝售后
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     *
     */
    public function refuse()
    {

        $id = I('post.id');

        $mobile = I('post.mobile');

        $number = I('post.number');

        $reason = I('post.reason');

        $data['id'] = $id;
        $data['progress'] = 3;
        $data['complete_time'] = NOW_TIME;
        $data['result'] = 2;
        $data['reason'] = $reason;

        $logic = D('Common/AfterSales','Logic');

        $result = $logic::update($data);

        if($result['code'] == 200)
        {

            $sms = new \Think\SMS\Mobile();

            $msg = "您申请的订单售后{$number}被拒绝,拒绝原因:$reason";

            $sms_res = $sms->send($mobile,$msg);

            $result['msg'] = $result['msg'].'|'.$sms_res['msg'];

        }


        $this->ajaxReturn($result);

    }
    /**
     * Introduction: 通过
     * @author: 杨陈鹏
     * @email: yangchenpeng@cdlinglu.com
     *
     */
    public function pass()
    {

        $id = I('post.id');

//        $mobile = I('post.mobile');
//
//        $number = I('post.number');

        $reason = I('post.reason');

        $data['id'] = $id;
        $data['progress'] = 3;
        $data['complete_time'] = NOW_TIME;
        $data['result'] = 1;
        $data['reason'] = $reason;

        $logic = D('Common/AfterSales','Logic');

        $result = $logic::update($data);

//        if($result['code'] == 200)
//        {
//
//            $sms = new \Think\SMS\Mobile();
//
//            $msg = "您申请的订单售后{$number}被拒绝,拒绝原因:$reason";
//
//            $sms->send($mobile,$msg);
//
//
//        }

        $this->ajaxReturn($result);

    }

}